package cn.xfdzx.android.apps.shop.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import cn.xfdzx.android.apps.shop.R;

/**
 * @author gzk
 * @date 2020/3/27 0027
 * description：社区零售的适配器
 */
public class CommunityRetailAdapter extends RecyclerView.Adapter {

    /**
     * 类型1：社区零售与市场采购切换
     * banner实现
     */
    public static final int TYPE_BANNER = 0;
    /**
     * 类型2：每日特价
     */
    public static final int TYPE_DAY = 1;

    /**
     * 类型3：附近商店
     */
    public static final int TYPE_SHOP = 2;

    /**
     * 当前类型
     */
    public int mCurrentType = TYPE_BANNER;

    private Context mContext;
    private final LayoutInflater mLayoutInflater;
    public HomeBannerViewHolder homeBannerViewHolder;
    public  HomeDayViewHolder homeDayViewHolder;
    public HomeShopViewHolder homeShopViewHolder;

    public CommunityRetailAdapter(Context mContext) {
        this.mContext = mContext;
//        this.moduleBeanList = moduleBeanList;
        //以后用它来初始化布局
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if (viewType == TYPE_BANNER) {
            return new HomeBannerViewHolder(mContext, mLayoutInflater.inflate(R.layout.item_home_banner, null));
        }else if (viewType == TYPE_DAY) {
            return new HomeDayViewHolder(mContext, mLayoutInflater.inflate(R.layout.item_home_day, null));
        }else if (viewType == TYPE_SHOP) {
            return new HomeShopViewHolder(mContext, mLayoutInflater.inflate(R.layout.item_home_shop, null));
        }
        return null;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if (getItemViewType(position) == TYPE_BANNER) {
            homeBannerViewHolder = (HomeBannerViewHolder) holder;

        }else if (getItemViewType(position) == TYPE_DAY) {
             homeDayViewHolder = (HomeDayViewHolder) holder;

        }else if (getItemViewType(position) == TYPE_SHOP) {
            homeShopViewHolder = (HomeShopViewHolder) holder;

        }
    }

    @Override
    public int getItemCount() {
        return 3;
    }

    @Override
    public int getItemViewType(int position) {
        switch (position) {
            case TYPE_BANNER:
                mCurrentType = TYPE_BANNER;
                break;
            case TYPE_DAY:
                mCurrentType = TYPE_DAY;
                break;
            case TYPE_SHOP:
                mCurrentType = TYPE_SHOP;
                break;
        }
        return mCurrentType;
    }
}
